#!/usr/bin/env python
# -*- coding:utf-8 -*-
import  Queue
import threading

class ThreadPool(object):
    def __init__(self,max_num=20):
        self.queque=Queue.Queue(max_num)
        for i in xrange(max_num):
            self.queque.put(threading.Thread)   #指向类，不创建对象，省内存空间
    def get_thread(self):
        return self.queque.get()
    def add_thread(self):
        self.queque.put(threading.Thread)   #low就low在这儿，得手动添加池线程

pool = ThreadPool(10)

def func(arg,p):
    print arg
    import time
    time.sleep(2)
    p.add_thread()

for i in xrange(30):
    thread = pool.get_thread()
    t= thread(target=func,args=(i,pool))